<#assign base=request.contextPath />
<!DOCTYPE html>
<div class="row">
	<div class="col-md-12 col-sm-12 col-xs-12">
		<div class="x_panel">
			<div class="x_title">
				<h2>资讯编辑 <small></small></h2>
				<div class="clearfix"></div>
			</div>
			<div class="x_content">
				<br/>
				<form id="postForm" data-parsley-validate class="form-horizontal form-label-left" method="post" action="${base}/gx/sysTicketType/save">
					<input type="hidden" id="id" name="id" value="${((obj.id)?c)!0 }">
		            <input type="hidden" name="addTime" value="${(obj.addTime)!.now?string['yyyy-MM-dd HH:mm:ss']}">
		            <input type="hidden" name="isDelete" value="${((obj.isDelete)?c)!0 }">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">产品名称 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="ticketType" name="ticketType" value="${(obj.ticketType)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">景点名称 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="scenicName" name="scenicName" value="${(obj.scenicName)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
		
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">出票类型 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="outTicket" name="outTicket" class="form-control select2">
                        		<option value="">请选择</option>
	                        		<option value="1">现购</option>
		                        	<option value="2">预购</option>
	                    	</select>
                        </div>
					</div>
				
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">门票图片 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="file" id="icon_dropify" name="file" class="dropify" data-default-file="${imagePath}${(obj.ticketImg)!''}" data-max-file-size="1M"/>
                            <input type="hidden" name="ticketImg" id="ticketImg" value="${(obj.ticketImg)!''}">
                            <input type="hidden" name="ticketImgOld" id="ticketImgOld" value="${(obj.ticketImg)!''}">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">门票单价 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="ticketPrice" name="ticketPrice" value="${(obj.ticketPrice)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">截止日期<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="closeTime" name="closeTime" value="${(obj.closeTime)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">出票单位<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="ticketUnit" name="ticketUnit" value="${(obj.ticketUnit)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">联系电话<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="contactNum" name="contactNum" value="${(obj.contactNum)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">具体地址<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="address" name="address" value="${(obj.address)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">门票信息<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="ticketInfo" name="ticketInfo" value="${(obj.ticketInfo)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
	
					<div class="ln_solid"></div>
					<div class="form-group">
						<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
							<button type="button" class="btn btn-success" id="submit">保存</button>
							<button type="button" class="btn btn-primary" id="goBack">返回</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
$(function() {
	//select2
	$(".select2").select2({width: "100%"});
	
	 $('.dropify').dropify({
     	messages: {
		        'default': '点击或拖拽文件到这里',
		        'replace': '点击或拖拽文件到这里来替换文件',
		        'remove':  '移除文件',
		        'error':   '对不起，你上传的文件太大了',
		    }
     });
     // Used events
     drEvent = $('#icon_dropify').dropify();
     drEvent.on('dropify.afterClear', function(event, element) {
     	$("#ticketImg").val("");
     });

     drEvent.on('dropify.errors', function(event, element) {
         console.log('Has Errors');
     });

	$("#goBack").click(function() {
		$("#main_content").load('${base}/gx/sysTicketType/list');	        
    });
	
	$("#submit").click(function() {
	
		var ticketType = $.trim($("#ticketType").val());
		var scenicName = $.trim($("#scenicName").val());
		var outTicket = $.trim($("#outTicket").val());
		var ticketInfo = $.trim($("#ticketInfo").val());
		var address = $.trim($("#address").val());
		var ticketPrice = $.trim($("#ticketPrice").val());
		var ticketUnit = $.trim($("#ticketUnit").val());
		
		if(ticketUnit==""){
    		swal("请输入出票单位");
            return;
    	}
		if(ticketPrice==""){
    		swal("请输入门票价格");
            return;
    	}
    	if(ticketType==""){
    		swal("请输入门票名称");
            return;
    	}
    	if(scenicName==""){
    		swal("请输入景点名称");
            return;
    	}
    	//获取数据
		drEvent = $('.dropify').dropify();
	    drEvent=drEvent.data('dropify')
	    if((drEvent.file.object !=null )){
	    	var ticketImg = drEvent.callBackBase64;
	    	ticketImg = ticketImg.substring(ticketImg.indexOf("base64")+7);
	    	$("#ticketImg").val(ticketImg);
	    }else{
	    	if($("#ticketImg").val()==""){
	    		swal("请上传门票图片");
	            return;
	    	}
	    }
    	if(outTicket==""){
    		swal("请选择出票类型");
            return;
    	}
    	if(ticketInfo==""){
    		swal("请输入门票信息");
            return;
    	}
    	if(address==""){
    		swal("请输入具体地址");
            return;
    	}

        $("#postForm").ajaxSubmit(function(data) {
    	 	if (data.flag) {
    	 		swal(data.msg, "", "success");
				$("#main_content").load('${base}/gx/sysTicketType/list');
    	 	} 
    	 	else {
    	 		swal(data.msg, "", "error");
    	 	}
    	});
	});
});

</script>